﻿using Microsoft.AspNetCore.SignalR;
using System;
using System.Threading.Tasks;

namespace CleanArchitecture.Infrastructure.Services.SignalR
{
    public class NotifyHub : Hub 
    {
        public override async Task OnConnectedAsync()
        {
            await base.OnConnectedAsync();
        }
        public override async Task OnDisconnectedAsync(Exception exception)
        {
            await base.OnDisconnectedAsync(exception);
        }
        /// <summary>
        /// 向客户端发送通知有新的系统消息
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public async Task OnNotifyNewNotice(string message)
        {
            #region Client
            //this.Context.ConnectionId                 //每个连接一个connectionId  表示唯一客户端
            //this.Clients.Client().SendAsync();        //指定发送消息
            //this.Clients.Clients()        
            #endregion             //给多个client发消息

            #region Group
            //this.Clients.Group();                     //给某个组发消息
            //this.Clients.Groups()                     //给多个组发消息
            //this.Groups.AddToGroupAsync()             //将指定连接加入组
            //this.Groups.RemoveFromGroupAsync()        //将指定连接移除组 
            #endregion

            await Clients.All.SendAsync("onNewNoticeAdd", DateTime.Now, message);
        }
    }
}
